import 'dart:core';

import 'package:apivideo_live_stream/apivideo_live_stream.dart';
import 'package:flutter_frame/app/modules/home/live/types/channel.dart';
import 'package:flutter_frame/app/modules/home/live/types/resolution.dart';
import 'package:flutter_frame/app/modules/home/live/types/sample_rate.dart';

List<int> fpsList = [24, 25, 30];
List<int> audioBitrateList = [32000, 64000, 128000, 192000];

String defaultValueTransformation(int e) {
  return '$e';
}

extension ListExtension on List<int> {
  Map<int, String> toMap({Function(int e) valueTransformation = defaultValueTransformation}) {
    final map = { for (var e in this) e : valueTransformation(e).toString() };
    return map;
  }
}

/// 视频配置
String bitrateToPrettyString(int bitrate) {
  return '${bitrate / 1000} Kbps';
}

class Params {
  final VideoConfig video = VideoConfig(
    bitrate: 1000000,
    fps: 20,
    resolution: Resolution.RESOLUTION_720
  );
  final AudioConfig audio = AudioConfig();

  String rtmpUrl = 'rtmp://117.173.156.97:38935/live/';
  String streamKey = '9527';

  String getResolutionToString() {
    return video.resolution.toPrettyString();
  }

  String getChannelToString() {
    return audio.channel.toPrettyString();
  }

  String getBitrateToString() {
    return bitrateToPrettyString(audio.bitrate);
  }

  String getSampleRateToString() {
    return audio.sampleRate.toPrettyString();
  }
}
